# include "scene.h"
# include <stdio.h>
# include <stdlib.h>

extern void mem_alloc(FILE *lptr, struct arr_struct *arr)
  {
   int i, j, k;
   short flag = 1;

   fprintf(lptr, "Entering into 'mem_alloc()'...\n"); 
   fprintf(lptr, "Trying to allocating memory for '%d' three-dimentional array(s)..\n", arr->nq);

   if( (arr->q = (double ****)malloc(arr->nq*sizeof(double ***))) == (double ****)0) flag = -1;
   else for(i = 0; i < arr->nq; i++)
       {
        if(flag == -1) break;

        if( (arr->q[i] = (double ***)malloc(arr->n1*sizeof(double **))) == (double ***)0) { flag = -1; break; }
        else for(j = 0; j < arr->n1; j++)
            {
              if(flag == -1) break;

              if( (arr->q[i][j] = (double **)malloc(arr->n2*sizeof(double *))) == (double **)0) { flag = -1; break; }
              else for(k = 0; k < arr->n2; k++)
                  if( (arr->q[i][j][k] = (double *)malloc(arr->n3*sizeof(double))) == (double *)0) { flag = -1; break; }
             }
       }

   if(flag == 1) fprintf(lptr, "..memory allocation done successfully!!\n");
   else{
        fprintf(lptr, "ERROR: unsufficient memory on the machine. Required amount of memory could not be allocated. Exiting the program!\n");
        exit(-1);
       }

   fprintf(lptr, "...'mem_alloc()' ends.\n");

   return;
  }
